<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>计时器</title>
	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
	<div id="app">
		<counter @change="counterChange" :count="3"></counter>
		<counter @change="counterChange" :count="2"></counter>
		{{total}}
	</div>
	<script>

		var counter = {
			props: ["count"],
			data: function() {
				return {
					number: this.counter //数据单项流通，避开子组件修改父组件传递的值
				}
			},
			template: "<div @click='handleCountClick'>{{number}}</div>",
			methods: {
				handleCountClick: function() {
					this.number ++
					this.$emit("change",1)
				}
			}
		}

		new Vue({
			el: "#app",
			components: {
				counter: counter
			},
			data: {
				total: 5
			},
			methods: {
				counterChange: function(number) {
					this.total += number
				}
			}
		})
	</script>
</body>
</html>